package solitaire.presentation;

import java.awt.Color;
import java.awt.Cursor;
import java.awt.FlowLayout;
import java.awt.Graphics;
import java.awt.event.MouseEvent;
import java.awt.event.MouseListener;

import javax.swing.JPanel;

import solitaire.controle.CColonne;
import solitaire.presentation.PSolitaire;

public class PColonne extends JPanel {

	PTasDeCartes cachees;
	PTasDeCartesAlternees visibles;
	CColonne controle;
	
	RetournerListener retournerListener;

	public PColonne(PTasDeCartes cachees, PTasDeCartesAlternees visibles,
			CColonne controle) {
		this.cachees = cachees;
		this.visibles = visibles;
		this.controle = controle;

		//setOpaque(false);
		//setBorder(null);
		setLayout(null);
		
		add(cachees, 0);
		add(visibles, 0);
		
		visibles.setLocation(0, cachees.getHeight());
		
		setSize(100, 500);
		setPreferredSize(getSize());
		
		retournerListener = new RetournerListener();
		activerRetournerCarte();
	}

//	public void paint(Graphics g) {
//		super.paint(g);
//		g.setColor(Color.blue);
//		g.drawRect(0, 0, getWidth() - 1, getHeight() - 1);
//	}

	class RetournerListener implements MouseListener {
		@Override
		public void mouseReleased(MouseEvent e) {
		}

		@Override
		public void mousePressed(MouseEvent e) {
		}

		@Override
		public void mouseExited(MouseEvent e) {
		}

		@Override
		public void mouseEntered(MouseEvent e) {
		}

		@Override
		public void mouseClicked(MouseEvent e) {
			try {
				controle.retournerCarte();
			} catch (Exception e1) {
				e1.printStackTrace();
			}
		}
	}
	
	public void activerRetournerCarte() {
		cachees.addMouseListener(retournerListener);
		cachees.setCursor(new Cursor(Cursor.WAIT_CURSOR));
	}

	public void desactiverRetournerCarte() {
		cachees.removeMouseListener(retournerListener);
	}

	public CColonne getControle() {
		return controle;
	}
}
